

// #include "device_data_struct.h"


#ifndef device_data_struct_h
#define device_data_struct_h

#include "plcgw_cfg.h"


//#define MAX_NAME_LEN   32 
//#define TEI_TAB_NUM    16


//------dev_type
typedef enum {
	DEV_TYPE_GATEWAY = 0,
	DEV_TYPE_COOLWARM_LAMP = 1,           // 双色灯， 博联格式-
	DEV_TYPE_PAD_6KEY = 0x0405,                // 面板开关 
	DEV_TYPE_ONECOLOR_LAMP = 0x0201,           // 单色灯， 新格式
	DEV_TYPE_TWOCOLOR_LAMP = 0x0202,           // 双色灯， 新格式
	DEV_TYPE_RGB_LAMP = 0x0203,
	DEV_TYPE_LCD_PANEL = 0x0406,					// 面板开关 
	DEV_TYPE_SCENE_PANEL = 0x0405,
	DEV_TYPE_RELAY_PANEL = 0x0404,
	//DEV_TYPE_DIMMER = 9,                // 调光器
	DEV_TYPE_BODY_DET = 0x0501,                // 人体检测
	//DEV_TEMPE_HUM = 11,                   // 温湿度
	//DEV_TYPE_ILLUMINANCE = 12,            // 光照度检测 
	DEV_TYPE_CURTAIN_MOTOR = 0x0301,          // 窗帘电机
	DEV_TYPE_MONO_LAMP = 14,          //  单色灯， 博联格式
	
	DEV_TYPE_BODY_DET_SH = 0x0501,
	DEV_TYPE_CIRCUIT_BREAKER = 0x0601,     // 断路器
	DEV_TYPE_METER_BREAKER = 0x0602,
	DEV_TYPE_RGBCW_LAMP = 0x0204,
	DEV_TYPE_ROADLAMP = 0x1111,           // 路灯
	DEV_TYPE_ROADLAMP_DOUBLE = 0x1313,    // 双色路灯


	DEV_TYPE_KT_BREAKER = 0x1001,         //  KTJ breaker
	DEV_TYPE_KT_BREAKER_2 = 0x1002,		  //  KTJ breaker
	DEV_TYPE_KT_BREAKER_3PH = 0x1003,		  //  KTJ breaker

	DEV_TYPE_ELE_METER     = 0x2001,   //  单相电表
	DEV_TYPE_ELE_METER_3PH = 0x2003,   // 3相电表


	DEV_TYPE_UNKNOWN = 0xffff           // 未知设备
	
} dev_type_t;

#define PID_ESPPLC_GW    "KTJ_plc_Gateway_A00001"
#define PID_DUAL_LAMP    "KTJ_plc_Light-2color_A00001"
#define PID_MONO_LAMP    "KTJ_plc_Light-1color_A00001"
#define PID_KEY_PANEL_6KEY    "KTJ_plc_panel6key_A00001"

#define PID_GATEWAY			"0102"

#define PID_LAMP_TWOCOLOR  	"0202"
#define PID_LAMP_ONECOLOR  	"0201"
#define PID_LAMP_RGB        "0203"
#define PID_LAMP_RGBCW      "0204"

#define PID_LCD_PANEL    	"0406"
#define PID_SCENE_PANEL   	"0405"
#define PID_RELAY_PANEL  	"0404"
#define PID_BODY_DET_SH     "0501"
#define PID_CIRCUIT_BREAKER "0601"    // 分支断路器
#define PID_METER_BREAKER   "0602"    // 电表后断路器

#define PID_DIMMER      	"dimmer"

#define PID_BODY_DETECT  	"BodyDet"
#define PID_TEMPE_HUM_BLE  	"Tempehum"
#define PID_ILLUMINANCE     "illuminance"
#define PID_CURTAIN_MOTOR   "0301"

#define PID_STR_ROADLAMP               "1111"   //  路灯
#define PID_STR_ROADLAMP_DOUBLE        "1313"   //  双色路灯


#define POWER_ROADLAMP               0   //  单色路灯
#define POWER_ROADLAMP_DOUBLE        1   //  双色路灯






#define PID_KT_BREAKER      "1001"   // KTJ 断路器


#define ATTR_NUM_COOLWARMLAMP   3
#define ATT_NUM_RGBLAMP         4


/*****
attr dpid , start from 1 , cannot be 0
*****/
enum {
	DPID_POWER = 1,
	DPID_BRIGHTNESS,
	DPID_CCT,
	DPID_R =4,
	DPID_G,
	DPID_B,
	DPID_KEYVALUE =7,
	DPID_KEYSTRING =8 ,
	DPID_BODY_STATUS = 9,
	DPID_DIMMING_CURR = 10,
	DPID_DIMMING_DELTA = 11,
	DPID_TEMPERATURE = 12,
	DPID_HUMIDITY = 13,
	DPID_RELAYVALUE = 14,
	DPID_RELAYSTRING,
	DPID_KEYBIND1 = 16,
	DPID_KEYRULER1 = 17,
	DPID_KEYBIND2 =18,
	DPID_KEYRULER2 = 19,
	DPID_KEYBIND3 = 20,
	DPID_KEYRULER3 = 21,
	DPID_KEYBIND4 = 22,
	DPID_KEYRULER4 = 23,
	DPID_KEYBIND5 = 24,
	DPID_KEYRULER5 = 25,
	DPID_KEYBIND6 = 26,
	DPID_KEYRULER6 = 27,
	DPID_KEYBIND7 = 28,
	DPID_KEYRULER7 = 29,
	DPID_KEYBIND8 = 30,
	DPID_KEYRULER8 = 31,
	DPID_ILLUMINANCE = 32,  // 流明
	DPID_OPSTATUS = 33,
	DPID_CURRPOSITION = 34,
	DPID_TARGETPOSITION = 35,
	DPID_MANUALEN = 36,
	DPID_KEYCONFIGSTR= 37,
	DPID_RELAYCONFIGSTR = 38,
	DPID_SW_STATUS = 39,
	DPID_Y=40,
	DPID_W=41,
	DPID_WIFI_SSID=42,
	DPID_WIFI_PASSWORD=43,
	DPID_SINGLE_KEYVAL = 44,
	DPID_SSID_LEN=45,
	DPID_PASSW_LEN=46,
	DPID_RELAYNUM = 47,

	DPID_LUM_DELTA = 48,  //光感差值
	DPID_DETECT_RANGE = 49, // 感应范围

	DPID_ACTIVEPOWER =50,  // 有功功率
	DPID_ACTIVEENERGY = 51, // 有功电能
	DPID_POWERFACTOR = 52,  // 功率因数
	DPID_VOLTAGE = 53,
	DPID_CURRENT = 54,
	DPID_ALARM_STATUE = 55,
	DPID_FREQ = 56,
	DPID_SWITCH_STATUS = 57,
	DPID_LOCK_STATUS = 58,

	DPID_DIMMING_CURVE = 59,  // 调光曲线
	DPID_DIMMING_TIME = 60,   // 调光时间（从0~最大亮度的时间）
	DPID_DIMING_FREQ =61,    // 调光频率
	
	DPID_PWRON_BRIGHT = 62,   // 上电默认亮度
	DPID_PWRON_CCT= 63,      // 上电默认色温
	
	// loadLamp dpid:
	DPID_DEV_STATUS = 64,
	DPID_DEV_CODE,
	DPID_IN_VOLT,
	DPID_IN_CURRENT,
	DPID_OUT_VOLT,
	DPID_OUT_CURRENT,
	DPID_LEAK_CURRENT = 70, // 漏电流
	DPID_ROADLAMP_GROUP_NUM,  // 组号
	DPID_TOTAL_ENERGY,   // 总电能
	
	DPID_TOTAL_LAMP_NUM, // 总灯号个数
	DPID_POLE_LEAK_VOLT,
	DPID_POLE_LEAK_CURRENT = 75,
	DPID_PLC_SNR,          //  PLC 信噪比
	DPID_PLC_attenuation,  // PLC 信号衰减
	DPID_NODE_MAC = 78,
	DPID_IN_VOLT_MIN,
	DPID_IN_VOLT_MAX = 80,
	DPID_TEST_MODE,
	DPID_LEAK_CURRENT_MAX,
	DPID_REPORT_INTERVAL,  // 上报间隔
	DPID_RATED_OUT_CURRENT_MAX,
	DPID_LIMITED_OUT_CURRENT_MAX,
	DPID_OUT_SAMPLE_RES,  // 输出采样电阻
	DPID_LIMITED_POWER,  // 限制功率
	DPID_DEVICE_TYPE,    //  设备型号
	DPID_LINKAGE_STATUS, // 联动状态
	DPID_RESET_PARAM = 90,     // 重置参数
	DPID_RAW_TO_NODE,    //   发给节点的透传数据
	DPID_RAW_FROM_NODE,  // 来自节点的透传数据
	
	DPID_MAX_POWER,
	DPID_BRIGHT_RD,      // ONLY FOR READ

	// 3 phase AC
	DPID_LINEVOLT_AB,
	DPID_LINEVOLT_AC,
	DPID_LINEVOLT_BC,
	DPID_VOLT_A,
	DPID_VOLT_B,
	DPID_VOLT_C = 100,
	DPID_VOLT_0,
	DPID_CURR_A,
	DPID_CURR_B,
	DPID_CURR_C,
	DPID_ACTPWR_A,
	DPID_ACTPWR_B,
	DPID_ACTPWR_C,
	DPID_REACTPWR_A,
	DPID_REACTPWR_B,
	DPID_REACTPWR_C = 110,
	DPID_PF_A,
	DPID_PF_B,
	DPID_PF_C,
	DPID_TEMPE_A,
	DPID_TEMPE_B,
	DPID_TEMPE_C,
	DPID_TEMPE_N,
	DPID_ENERGY_A,
	DPID_ENERGY_B,
	DPID_ENERGY_C = 120,
	DPID_ENERGY_TOTAL,
	DPID_OUT_LEAKAGE,

	DPID_cntOverVoltA,
	DPID_cntOverVoltB,
	DPID_cntOverVoltC,
	DPID_cntUnderVoltA,
	DPID_cntUnderVoltB,
	DPID_cntUnderVoltC,
	DPID_cntLeakege,
	DPID_cntOverTempe = 130,
	DPID_cntOverCurrA,
	DPID_cntOverCurrB,
	DPID_cntOverCurrC,
	DPID_cntFaultTotal,
	DPID_cntSelfTest,
	DPID_cntONOff,
	DPID_cntRsv,
	DPID_faultReason,
	DPID_faultTime,
	DPID_faultVoltA = 140,
	DPID_faultVoltB,
	DPID_faultVoltC,
	DPID_faultCurrA,
	DPID_faultCurrB,
	DPID_faultCurrC,
	DPID_faultCurrLeakage,
	DPID_faultTempeA,
	DPID_faultTempeB,
	DPID_faultTempeC,
	DPID_faultTempeN = 150,
	DPID_faultOutLeakage,

	DPID_REACTIVEPOWER,

	
	DPID_FLAG_FAULT_OverVoltA,
	DPID_FLAG_FAULT_OverVoltB,
	DPID_FLAG_FAULT_OverVoltC,
	DPID_FLAG_FAULT_UnderVoltA,
	DPID_FLAG_FAULT_UnderVoltB,
	DPID_FLAG_FAULT_UnderVoltC,
	DPID_FLAG_FAULT_Leakege,
	DPID_FLAG_FAULT_OverTempe = 160,
	DPID_FLAG_FAULT_OverCurrA,
	DPID_FLAG_FAULT_OverCurrB,
	DPID_FLAG_FAULT_OverCurrC,
	DPID_FLAG_FAULT_SWITCH_OFF,
	DPID_FLAG_FAULT_SWITCH_ON,
	DPID_FLAG_FAULT_SHORT,
	DPID_FLAG_FAULT_WATER,
	DPID_FLAG_FAULT_OUT_LEAKAGE,

	DPID_PROTECT_MASK,
	DPID_THRESHOLD_OVER_VOLT = 170,
	DPID_THRESHOLD_UNDER_VOLT,
	DPID_THRESHOLD_LEAKAGE_CURR,
	DPID_THRESHOLD_TEMPE,
	DPID_THRESHOLD_TEMPE_PROCTEC_TIME,
	DPID_THRESHOLD_MAX_CURR,
	DPID_THRESHOLD_OUT_LEAKAGE_CURR,
	
	
	
	DPID_PASSWD_PARAM,
	DPID_PASSWD_ID,
	DPID_PASSWD_ID2,
	DPID_PASSWD_ID4,
	DPID_PASSWD_CTRL,
	DPID_DO_CODE,
	
	
	
	
	
	DPID_DEVICETYPE = 0xff00,
	DPID_VENDORCODE ,
	DPID_FWVER,
	DPID_HWVER,
	DPID_PROTOCOL_VER,
	DPID_PID,
	DPID_FWVER_ASC,
	DPID_HWVER_ASC,
	

	DPID_FAULTCODE = 0xfff0,
	
};


#define DATA_TYPE_HEX_FLAG  0x80
enum {
	DATA_TYPE_BOOL,
	DATA_TYPE_UINT16,	
	DATA_TYPE_INT16,
	DATA_TYPE_UINT32,
	DATA_TYPE_INT32,
	DATA_TYPE_FLOAT,
	DATA_TYPE_UINT64,
	DATA_TYPE_INT64,
	DATA_TYPE_DOUBLE,
	DATA_TYPE_ASC,     // ASCII 码
	DATA_TYPE_STRING,  // 长字符串
	DATA_TYPE_BCD,   //  BCD , <=16字 (8byte)
	DATA_TYPE_HEX,  
	DATA_TYPE_LONG_HEX,  //  长串的8位字节数据
	DATA_TYPE_LONG_ASC,  //  长串的8位字节数据
	DATA_TYPE_BIT,
	DATA_TYPE_BIT_INVERT,   // bit取反
    /*	
	DATA_TYPE_HEX1 = DATA_TYPE_HEX_FLAG+1,     // hex 1 byte
	DATA_TYPE_HEX2 = DATA_TYPE_HEX_FLAG+2,     // hex 2 byte
	DATA_TYPE_HEX3 = DATA_TYPE_HEX_FLAG+3,     // hex 3 byte
	DATA_TYPE_HEX4 = DATA_TYPE_HEX_FLAG+4,     // hex 4 byte
	DATA_TYPE_HEX5 = DATA_TYPE_HEX_FLAG+5,     // hex 5 byte
	DATA_TYPE_HEX6 = DATA_TYPE_HEX_FLAG+6,     // hex 6 byte
	DATA_TYPE_HEX7 = DATA_TYPE_HEX_FLAG+7,     // hex 7 byte
	DATA_TYPE_HEX8 = DATA_TYPE_HEX_FLAG+8,     // hex 8 byte
	*/
};

typedef struct {
	char str[16];
	int data_type;
	int reg_cnt;
}data_type_str_num_t;;


typedef struct {
	unsigned short dev_type;
	unsigned char attr_len;
	unsigned char key_num;   //  按键面板类型的键数量
	unsigned char rsv2;
	char pid[MAX_PID_LEN];
	char name[MAX_NAME_LEN];
}device_def_t;




#endif

